create_links() {
    # create soname links
    find "$PKG" -type f -name '*.so*' ! -path '*xorg/*' -print0 | while read -d $'\0' _lib; do
        _soname=$(dirname "${_lib}")/$(readelf -d "${_lib}" | grep -Po 'SONAME.*: \[\K[^]]*' || true)
        _base=$(echo ${_soname} | sed -r 's/(.*).so.*/\1.so/')
        [[ -e "${_soname}" ]] || ln -s $(basename "${_lib}") "${_soname}"
        [[ -e "${_base}" ]] || ln -s $(basename "${_soname}") "${_base}"
    done
}
    
    sh "/sources/NVIDIA-Linux-x86_64-$surum.run" --extract-only
    cd "NVIDIA-Linux-x86_64-$surum"
    bsdtar -xf nvidia-persistenced-init.tar.bz2

    cd kernel
    sed -i "s/__VERSION_STRING/${surum}/" dkms.conf
    sed -i 's/__JOBS/`nproc`/' dkms.conf
    sed -i 's/__DKMS_MODULES//' dkms.conf
    sed -i '$iBUILT_MODULE_NAME[0]="nvidia"\
DEST_MODULE_LOCATION[0]="/kernel/drivers/video"\
BUILT_MODULE_NAME[1]="nvidia-uvm"\
DEST_MODULE_LOCATION[1]="/kernel/drivers/video"\
BUILT_MODULE_NAME[2]="nvidia-modeset"\
DEST_MODULE_LOCATION[2]="/kernel/drivers/video"\
BUILT_MODULE_NAME[3]="nvidia-drm"\
DEST_MODULE_LOCATION[3]="/kernel/drivers/video"' dkms.conf

    # Gift for linux-rt guys
    sed -i 's/NV_EXCLUDE_BUILD_MODULES/IGNORE_PREEMPT_RT_PRESENCE=1 NV_EXCLUDE_BUILD_MODULES/' dkms.conf
 
 
 cd $SRC/"NVIDIA-Linux-x86_64-$surum"    
        # OpenCL
  install -D -m644 nvidia.icd "${PKG}/etc/OpenCL/vendors/nvidia.icd"
  install -D -m755 "libnvidia-compiler.so.${surum}" "${PKG}/usr/lib/libnvidia-compiler.so.${surum}"
  install -D -m755 "libnvidia-opencl.so.${surum}" "${PKG}/usr/lib/libnvidia-opencl.so.${surum}"
  # create_links

cd $SRC/"NVIDIA-Linux-x86_64-$surum" 

     install -dm 755 "${PKG}"/usr/src
    cp -dr --no-preserve='ownership' kernel "${PKG}/usr/src/nvidia-${surum}"

    echo "blacklist nouveau" |
        install -Dm644 /dev/stdin "${PKG}/usr/lib/modprobe.d/${isim}.conf"
        
   
    # X driver
    install -D -m755 nvidia_drv.so "${PKG}/usr/lib/xorg/modules/drivers/nvidia_drv.so"

    # firmware
  #  install -D -m644 firmware/gsp.bin "${PKG}/usr/lib/firmware/nvidia/${surum}/gsp.bin"

    # GLX extension module for X
    install -D -m755 "libglxserver_nvidia.so.${surum}" "${PKG}/usr/lib/nvidia/xorg/libglxserver_nvidia.so.${surum}"
    # Ensure that X finds glx
    ln -s "libglxserver_nvidia.so.${surum}" "${PKG}/usr/lib/nvidia/xorg/libglxserver_nvidia.so.1"
    ln -s "libglxserver_nvidia.so.${surum}" "${PKG}/usr/lib/nvidia/xorg/libglxserver_nvidia.so"

    install -D -m755 "libGLX_nvidia.so.${surum}" "${PKG}/usr/lib/libGLX_nvidia.so.${surum}"

    # OpenGL libraries
    install -D -m755 "libEGL_nvidia.so.${surum}" "${PKG}/usr/lib/libEGL_nvidia.so.${surum}"
    install -D -m755 "libGLESv1_CM_nvidia.so.${surum}" "${PKG}/usr/lib/libGLESv1_CM_nvidia.so.${surum}"
    install -D -m755 "libGLESv2_nvidia.so.${surum}" "${PKG}/usr/lib/libGLESv2_nvidia.so.${surum}"
    install -D -m644 "10_nvidia.json" "${PKG}/usr/share/glvnd/egl_vendor.d/10_nvidia.json"

    # OpenGL core library
    install -D -m755 "libnvidia-glcore.so.${surum}" "${PKG}/usr/lib/libnvidia-glcore.so.${surum}"
    install -D -m755 "libnvidia-eglcore.so.${surum}" "${PKG}/usr/lib/libnvidia-eglcore.so.${surum}"
    install -D -m755 "libnvidia-glsi.so.${surum}" "${PKG}/usr/lib/libnvidia-glsi.so.${surum}"

    # misc
    install -D -m755 "libnvidia-ifr.so.${surum}" "${PKG}/usr/lib/libnvidia-ifr.so.${surum}"
    install -D -m755 "libnvidia-fbc.so.${surum}" "${PKG}/usr/lib/libnvidia-fbc.so.${surum}"
    install -D -m755 "libnvidia-encode.so.${surum}" "${PKG}/usr/lib/libnvidia-encode.so.${surum}"
    install -D -m755 "libnvidia-cfg.so.${surum}" "${PKG}/usr/lib/libnvidia-cfg.so.${surum}"
    install -D -m755 "libnvidia-ml.so.${surum}" "${PKG}/usr/lib/libnvidia-ml.so.${surum}"
    install -D -m755 "libnvidia-ngx.so.${surum}" "${PKG}/usr/lib/libnvidia-ngx.so.${surum}"
    install -D -m755 "libnvidia-glvkspirv.so.${surum}" "${PKG}/usr/lib/libnvidia-glvkspirv.so.${surum}"

    # Vulkan ICD
    install -D -m644 "nvidia_icd.json" "${PKG}/usr/share/vulkan/icd.d/nvidia_icd.json"
    install -D -m644 "nvidia_layers.json" "${PKG}/usr/share/vulkan/implicit_layer.d/nvidia_layers.json"

    # VDPAU
    install -D -m755 "libvdpau_nvidia.so.${surum}" "${PKG}/usr/lib/vdpau/libvdpau_nvidia.so.${surum}"

    # nvidia-tls library
    install -D -m755 "libnvidia-tls.so.${surum}" "${PKG}/usr/lib/libnvidia-tls.so.${surum}"

    # CUDA
    install -D -m755 "libcuda.so.${surum}" "${PKG}/usr/lib/libcuda.so.${surum}"
    install -D -m755 "libnvcuvid.so.${surum}" "${PKG}/usr/lib/libnvcuvid.so.${surum}"

    # PTX JIT Compiler (Parallel Thread Execution (PTX) is a pseudo-assembly language for CUDA)
    install -D -m755 "libnvidia-ptxjitcompiler.so.${surum}" "${PKG}/usr/lib/libnvidia-ptxjitcompiler.so.${surum}"

    # raytracing
    install -D -m755 "libnvoptix.so.${surum}" "${PKG}/usr/lib/libnvoptix.so.${surum}"
    install -D -m755 "libnvidia-rtcore.so.${surum}" "${PKG}/usr/lib/libnvidia-rtcore.so.${surum}"
    install -D -m755 "libnvidia-cbl.so.${surum}" "${PKG}/usr/lib/libnvidia-cbl.so.${surum}"

    # Optical flow
    install -D -m755 "libnvidia-opticalflow.so.${surum}" "${PKG}/usr/lib/libnvidia-opticalflow.so.${surum}"

    # DEBUG
    install -D -m755 nvidia-debugdump "${PKG}/usr/bin/nvidia-debugdump"

    # nvidia-xconfig
    install -D -m755 nvidia-xconfig "${PKG}/usr/bin/nvidia-xconfig"
    install -D -m644 nvidia-xconfig.1.gz "${PKG}/usr/share/man/man1/nvidia-xconfig.1.gz"

    # nvidia-bug-report
    install -D -m755 nvidia-bug-report.sh "${PKG}/usr/bin/nvidia-bug-report.sh"

    # nvidia-smi
    install -D -m755 nvidia-smi "${PKG}/usr/bin/nvidia-smi"
    install -D -m644 nvidia-smi.1.gz "${PKG}/usr/share/man/man1/nvidia-smi.1.gz"

    # nvidia-cuda-mps
    install -D -m755 nvidia-cuda-mps-server "${PKG}/usr/bin/nvidia-cuda-mps-server"
    install -D -m755 nvidia-cuda-mps-control "${PKG}/usr/bin/nvidia-cuda-mps-control"
    install -D -m644 nvidia-cuda-mps-control.1.gz "${PKG}/usr/share/man/man1/nvidia-cuda-mps-control.1.gz"

    # nvidia-modprobe
    # This should be removed if nvidia fixed their uvm module!
    install -D -m4755 nvidia-modprobe "${PKG}/usr/bin/nvidia-modprobe"
    install -D -m644 nvidia-modprobe.1.gz "${PKG}/usr/share/man/man1/nvidia-modprobe.1.gz"

    # nvidia-persistenced
    install -D -m755 nvidia-persistenced "${PKG}/usr/bin/nvidia-persistenced"
    install -D -m644 nvidia-persistenced.1.gz "${PKG}/usr/share/man/man1/nvidia-persistenced.1.gz"
 #   install -D -m644 nvidia-persistenced-init/systemd/nvidia-persistenced.service.template "${PKG}/usr/lib/systemd/system/nvidia-persistenced.service"
 #   sed -i 's/__USER__/nvidia-persistenced/' "${PKG}/usr/lib/systemd/system/nvidia-persistenced.service"

    # application profiles
    install -D -m644 nvidia-application-profiles-${surum}-rc "${PKG}/usr/share/nvidia/nvidia-application-profiles-${surum}-rc"
    install -D -m644 nvidia-application-profiles-${surum}-key-documentation "${PKG}/usr/share/nvidia/nvidia-application-profiles-${surum}-key-documentation"


    # new power management support
  #  install -D -m644 systemd/system/nvidia-suspend.service "${PKG}/usr/lib/systemd/system/nvidia-suspend.service"
  #  install -D -m644 systemd/system/nvidia-hibernate.service "${PKG}/usr/lib/systemd/system/nvidia-hibernate.service"
  #  install -D -m644 systemd/system/nvidia-resume.service "${PKG}/usr/lib/systemd/system/nvidia-resume.service"
  #  install -D -m755 systemd/system-sleep/nvidia "${PKG}/usr/lib/systemd/system-sleep/nvidia"
  #  install -D -m755 systemd/nvidia-sleep.sh "${PKG}/usr/bin/nvidia-sleep.sh"

    # distro specific files must be installed in /usr/share/X11/xorg.conf.d
    install -D -m644 "$SRC/10-nvidia-drm-outputclass.conf" "${PKG}/usr/share/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf"

    install -Dm644 "$SRC/nvidia-utils.sysusers" "${PKG}/usr/lib/sysusers.d/$isim.conf"

    create_links
        